package com.space.school.service.impl;

import com.space.school.dao.InfoDao;
import com.space.school.dao.impl.InfoDaoImpl;
import com.space.school.domain.Info;
import com.space.school.service.InfoService;
import com.space.school.utils.PageBean;

import java.util.List;
import java.util.Map;
import java.util.Random;

public class InfoServiceImpl implements InfoService {
    InfoDao infodao=new InfoDaoImpl();

    @Override
    public PageBean<Info> search(Map<String, String[]> map, int currentPage, int pageSize) {
        int start = (currentPage - 1) * pageSize;
        List<Info> list=infodao.search(map,start,pageSize);
        PageBean<Info> pb=new PageBean<>();
        pb.setList(list);
//        总数据数
        int count=infodao.count(map);
        pb.setTotalCount(count);
//       每页显示数据数
        pb.setRows(pageSize);
//        当前页数
        pb.setCurrentPage(currentPage);
//        总页数
        int totalPage=(int) Math.ceil((double) count/pageSize);
        pb.setTotalPage(totalPage);
        return pb;
    }

    @Override
    public void del(int product_id) {
        infodao.del(product_id);
    }

    @Override
    public Info find(int product_id) {
        return infodao.find(product_id).get(0);

    }

    @Override
    public void update(Info info) {
        infodao.update(info);
    }

    @Override
    public void update2(Map<String, String[]> map) {
        infodao.update2(map);
    }

    @Override
    public int add(Info info) {
        return infodao.insert(info);
    }

    @Override
    public List<Info> findAll() {
        return infodao.findAll();
    }

    @Override
    public List<Info> findByUser(String order_id) {
        return infodao.findByUser(order_id);
    }

}
